home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / imlib / convert.c next >
C/C++ Source or Header  |  1997-05-20  |  933b  |  40 lines

  1. /* Jonathan Clark April 5, 93   Converts Unix file for to DOS & vice versa. */
  2. #include <stdio.h>
  3.  
  4. #define STReq(x,y) (!strcmp(x,y))
  5. main(int argc, char **argv)
  6. {
  7.   FILE *fp,*o;
  8.   int i,strip,add,c;
  9.   char st[100];
  10.   if (argc<3 || !(STReq(argv[1],"2unix") || STReq(argv[1],"2dos")))
  11.   { printf("Usage : convert [2unix]|[2dos] files\n");
  12.     exit(0);
  13.   }
  14.   if (STReq(argv[1],"2unix"))
  15.   { strip=1; add=0; }
  16.   else {strip=0; add=1; }
  17.   printf("Converting...\n");
  18.   for (i=2;i<argc;i++)
  19.   {
  20.     printf("  %s\n",argv[i]);
  21.     fp=fopen(argv[i],"r"); 
  22.     o=fopen("testXDF.out","w");
  23.     while (!feof(fp))
  24.     {
  25.       c=fgetc(fp);
  26.       if (c>=0)
  27.       {
  28.         if (c=='\n' && add) { fputc('\r',o); }
  29.         if (!(c=='\r') || !strip)
  30.           fputc(c,o); 
  31.       }
  32.     }
  33.     fclose(o);
  34.     fclose(fp);
  35.     sprintf(st,"cp testXDF.out %s",argv[i]);
  36.     system(st);
  37.     unlink("testXDF.out"); 
  38.   } 
  39. }
  40.